package com.fulihui.wgj.admin.api.wxtemplate;

import com.fulihui.common.builder.web.JsonResultBuilder;
import com.fulihui.common.result.web.Result;
import com.fulihui.wgj.admin.api.base.BaseController;
import com.fulihui.wgj.admin.api.wxtemplate.request.GameInfoRequest;
import com.fulihui.wgj.admin.api.wxtemplate.vo.GameInfoVO;
import com.fulihui.wgj.admin.api.wxtemplate.vo.GameTagVO;
import com.fulihui.wgj.admin.integration.GamePlatformServiceClient;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author: Levon
 * @date: 2018-08-07 13:40
 */
@RestController
@RequestMapping("/game")
@Api(tags = "游戏分类查询相关接口")
public class GameTagController extends BaseController {

    @Autowired
    private GamePlatformServiceClient gamePlatformServiceClient;

    @RequestMapping(value = "/category/list", method = RequestMethod.POST)
    @ApiOperation("获取游戏分类列表")
    public Result<List<GameTagVO>> queryGameCategory(HttpServletRequest servletRequest) {
        List<GameTagVO> gameTagVOS = gamePlatformServiceClient.queryAllGameCategory();
        return JsonResultBuilder.succ(gameTagVOS);
    }

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation("根据分类id获取游戏列表")
    public Result<List<GameInfoVO>> queryGameCategory(@RequestBody GameInfoRequest request) {
        List<String> ids = Lists.newArrayList();
        String categoryids = request.getCategoryids();
        if (!StringUtils.isEmpty(categoryids)) {
            ids = Splitter.on(",").trimResults().splitToList(categoryids);
        }
        List<GameInfoVO> gameInfoVOS = gamePlatformServiceClient.queryGameInfoByIds(ids);
        return JsonResultBuilder.succ(gameInfoVOS);
    }
}
